package com.burgeon.backend.Rest.User;
/**
 * 获取用户信息
 */


import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.User;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class GetUserCount extends RESTBase {
    private final static String RANGE = "50";//分页数量

    private String ip;
    private String account;
    private String password;

    public GetUserCount(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(int start) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(start), url);
//        System.err.println(str);
//        HashMap rows = new HashMap();
//        String code = new JSONArray(str).getJSONObject(0).getString("code");
//        if (!"0".equals(code)){
//            throw new Exception(str);
//        }
        String count = new JSONArray(str).getJSONObject(0).getString("count");
//        System.err.println(count);

        return count;
    }

    private MultiValueMap Data(int y) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("ID");


        params.put("columns", columns);
        params.put("table", "C_VIP");//表名

        params.put("range", 2000);
        params.put("count", "true");
//        int r = Integer.valueOf(RANGE);
//        params.put("start", String.valueOf(y * r));
//        System.err.println(params);
        return DATA("Query", params, account, password);
    }

    public static void main(String[] args) {
        GetUserCount g = new GetUserCount("59.110.28.94:90", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println(g.getData(0));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
